﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DreamBox.Admin.User
{
    public partial class CompetenceAdd : BLL.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DAL.Admin.GetCompetence com = new DAL.Admin.GetCompetence();
                DropParentID.DataSource = com.GetList();
                DropParentID.DataTextField = "CompetenceName";
                DropParentID.DataValueField = "ComID";
                DropParentID.DataBind();

                DropParentID.Items.Insert(0,new ListItem("无上级权限","0"));

                //
                if (Request.QueryString["ComID"] != null)
                {
                    foreach (ListItem item in DropParentID.Items)
                    {
                        if (item.Value == Request.QueryString["ComID"])
                        {
                            item.Selected = true;
                        }
                    }
                }
            }
        }

        protected void btnPost_Click(object sender, EventArgs e)
        {
            Model.Admin.Competence m = new Model.Admin.Competence();
            m.CompetenceName = ComName.Text;
            m.Url = ComUrl.Text;
            m.NodeCount = int.Parse(NodeCount.Text);
            m.IsType = 1;
            m.ParentID = int.Parse(DropParentID.SelectedValue);
            DAL.Admin.Competence com = new DAL.Admin.Competence();
            if (com.Add(m))
            {
                BLL.Admin.Tips.DetailedTips(this, "添加成功", "/User/CompetenceAdd.aspx","1");
            }
        }
    }
}